<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.mfp.java.testYou.core.servlets.ManageTestServlet" %>
<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="../global/global.jsp" %>
<%TestPage testPage = new TestPage(request, response);%>
<c:set var="testPage" value="<%=testPage%>"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../components/htmlHeader.jsp"></jsp:include>
    <title><testU:i18n>testPage.title</testU:i18n></title>
    <script language="JavaScript" src="<%=cPath%>/testYou/resources/validations.js">
    </script>
</head>
<body class="bgColor textColor">
<jsp:include page="../components/header.jsp"/>

<br><br>
<%if (testPage.hasMessage()) { %>
<center><testU:i18n>${testPage.getMessage()}</testU:i18n></center>
<%} %>
<br>

<form action="<%=cPath%><%=response.encodeURL(ManageTestServlet.URL)%>" method="post" id="newTestFormId"
      onsubmit="return checkFormTest(this)">
    <c:if test="${testPage.edit}">
        <input type="hidden" name="<%=ManageTestServlet.INPUT_TESTID%>" value="${testPage.testId}"/>
    </c:if>
    <table class="centerTable40marg width20 textColor">
        <tbody>
        <tr>
            <td>
                <label for="testName"><testU:i18n>testPage.name</testU:i18n></label>
            </td>
            <td>
                <c:set var="inputName" value="<%=ManageTestServlet.INPUT_NAME%>"/>
                <input id="testName" type="text" name="${inputName}"
                       value="${testPage.testTitle}" onblur="enableButtonAddTest('addTestButton', 'testName')"/>
            </td>
        <tr>
            <td>
                <c:if test="${testPage.edit}">
                    <label for="final"><testU:i18n>testPage.final</testU:i18n></label>
            </td>
            <td>
                <input id="final" type="checkbox" name="<%=ManageTestServlet.INPUT_FINAL%>"/>
                <c:if test="${testPage.isFinal()}">
                    <script type="text/javascript">
                        document.getElementById("final").checked = "checked";
                    </script>
                </c:if>
                </c:if>
            </td>
        </tr>
        <tr>
            <td>
                <label for="hint"><testU:i18n>testPage.allowHint</testU:i18n></label>
            </td>
            <td>
                <input id="hint" type="checkbox"
                       name="<%=ManageTestServlet.INPUT_ALLOW_HINT%>"/>
                <c:if test="${testPage.hintAllowed}">
                    <script type="text/javascript">
                        document.getElementById("hint").checked = "checked";
                    </script>
                </c:if>
            </td>

        </tr>
        <tr class="alignCenter">
            <td>
                <form><input class="width80px" type="button" value="Back"
                             onClick="window.location.href='<%=cPath%>/testYou/pages/tests.jsp'">
                </form>
            </td>
            <td>
                <c:choose>
                    <c:when test="${testPage.edit}">
                        <input type="hidden" name="<%=ManageTestServlet.OPERATION%>"
                               value="<%=ManageTestServlet.OPERATION_CHANGE%>"/>
                        <input type="submit" value='<testU:i18n>testPage.editDet</testU:i18n>'/>
                    </c:when>
                    <c:otherwise>
                        <input type="hidden" name="<%=ManageTestServlet.OPERATION%>"
                               value="<%=ManageTestServlet.OPERATION_CREATE_NEW%>"/>
                        <input disabled="disabled" id="addTestButton" type="submit" value='<testU:i18n>testPage.crNew</testU:i18n>'/>
                    </c:otherwise>
                </c:choose>
            </td>
        </tr>
        <tr>
            <td>&nbsp</td>
        </tr>
        </tbody>
    </table>
</form>

<c:if test="${testPage.edit}">
    <c:forEach items="${testPage.questions}" var="question">
        <form action="<%=cPath%><%=response.encodeURL(ManageTestServlet.URL)%>" method="post">
            <table class="centerTable40marg width20">
                <tbody>
                <tr>
                    <td>
                        <p>${question.text}</p>
                    </td>
                    <input type="hidden" name="<%=ManageTestServlet.INPUT_TESTID%>" value="${testPage.testId}"/>
                    <input type="hidden" name="<%=ManageTestServlet.OPERATION%>"
                           value="<%=ManageTestServlet.OPERATION_DEL_QUESTION%>"/>
                    <input type="hidden" name="<%=ManageTestServlet.INPUT_QUESTIONID%>" value="${question.id}"/>
                    <td>
                        <input type="submit" value="x"/>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
        <br/>
    </c:forEach>

    <form action="<%=cPath%><%=response.encodeURL(ManageTestServlet.URL)%>" method="post" name="testForm">
        <table class="centerTable40marg width20">
            <tbody>
            <tr>
                <input type="hidden" name="<%=ManageTestServlet.INPUT_TESTID%>" value="${testPage.testId}"/>
                <input type="hidden" id="hiddenField" name="<%=ManageTestServlet.OPERATION%>"
                       value="<%=ManageTestServlet.OPERATION_ADD_QUESTION%>"/>
                <td>
                    <tU:selectListComponent editButtonId="addQueButton" formName="testForm" validate="true"/>
                </td>
                <c:set value="<%=ManageTestServlet.OPERATION_ADD_QUESTION%>" var="addQuest"/>
                <td class="alignCenter">
                    <input type="submit" disabled="disabled" id="addQueButton"
                           value='<testU:i18n>testPage.addQuestion</testU:i18n>'/>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</c:if>
</body>
</html>
